﻿using MvcContrib.FluentHtml.Elements;

namespace GiveAQuiz.Web.Helpers
{
  /// <summary>
  /// Extension methods for easily adding meta-data to Html elements
  /// which can be used by the jQuery validation plugin.
  /// </summary>
  public static class JQueryValidationExtensions
  {
    /// <summary>
    /// Extension method that will add the "required" class to 
    /// an Html &lt;input type="text" /&gt; element.
    /// </summary>
    /// <param name="textBox">The MvcContrib TextBox object.</param>
    /// <returns>A reference to the same MvcContrib TextBox 
    /// object.</returns>
    public static TextBox ValidateForRequired(this TextBox textBox)
    {
      return textBox.Class("required");
    }

    /// <summary>
    /// Extension method that will add the "email" class to 
    /// an Html &lt;input type="text" /&gt; element.
    /// </summary>
    /// <param name="textBox">The MvcContrib TextBox object.</param>
    /// <returns>A reference to the same MvcContrib TextBox 
    /// object.</returns>
    public static TextBox ValidateForEmail(this TextBox textBox)
    {
      return textBox.Class("email");
    }

    /// <summary>
    /// Extension method that will add the "required" class to 
    /// an Html &lt;input type="password" /&gt; element.
    /// </summary>
    /// <param name="textBox">The MvcContrib Password object.</param>
    /// <returns>A reference to the same MvcContrib Password 
    /// object.</returns>
    public static Password ValidateForRequired(this Password pw)
    {
      return pw.Class("required");
    }

    /// <summary>
    /// Extension method that will add the "minlength" attribute to 
    /// an Html &lt;input type="password" /&gt; element.
    /// </summary>
    /// <param name="textBox">The MvcContrib Password object.</param>
    /// <returns>A reference to the same MvcContrib Password 
    /// object.</returns>
    public static Password ValidateForMinLength(this Password pw, int length)
    {
      return pw.Attr("minlength", length);
    }    
  }
}